﻿/*!
 * JaernCloud JavaScript Library 0.1 Alpha
 *
 * Copyright 2010, The JaernCloud Project
 *
*/

(function( window, undefined ) {

// Define a local copy of JaernCloud
var jaerncloud = function( selector, context ) {
    
    //

};

jaerncloud.utils = jaerncloud.prototype = {

};

jaerncloud.ajax = function (actionSelector) {
    var request = {
        action: actionSelector
    };
    var json = JSON.stringify(request);
    $.ajax({
        url: 'DoAjax',
        type: 'POST',
        data: json,
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        success: function (data) {
            if(data.render) {
                for (var id in data.render) {
                    var target = $(id);
                    if(target) {
                        // TODO: Only replace inner content
                        $(target).replaceWith(data.render[id]);
                    }
                }
            }
        }
    });
    return false;
};


// Expose JaernCloud to the global object
window.jaerncloud = window.$.jcl = jaerncloud;

})(window);
